package com.fangyi.yunmusic.aspect;

import com.fangyi.yunmusic.utils.JsonResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;


@Component
@Aspect
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class JsonResultAspect {

    @Pointcut("execution(* com.fangyi.yunmusic.controller..*.*(..))")
    private void check(){}


    @Around("check()")
    public JsonResult around(ProceedingJoinPoint pjp) throws Throwable{
        JsonResult result;

        Object data = pjp.proceed();
        if (data == null) {
            result = JsonResult.ok();
        } else {
            result = JsonResult.ok(data);
        }

        return result;
    }
}
